import 'package:flutter/material.dart';
import 'package:date_format/date_format.dart';

class TimeOtherPage extends StatefulWidget {
  TimeOtherPage({Key key}) : super(key: key);

  @override
  _TimeOtherPageState createState() => _TimeOtherPageState();
}

class _TimeOtherPageState extends State<TimeOtherPage> {
  DateTime _dateTime = new DateTime.now();

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    var now = DateTime.now();

    // print(now); //打印当前时间
    // print(now.millisecondsSinceEpoch); //时间戳
    // //时间戳转换时间
    // print(DateTime.fromMillisecondsSinceEpoch(now.millisecondsSinceEpoch));

    // print(formatDate(DateTime.now(), [yyyy, '年', mm, '月', dd]));
  }

  _showDatePicker() {
    // DatePicker.showDatePicker(
    //   context,
    //   pickerTheme: DateTimePickerTheme(
    //     showTitle: true,
    //     confirm: Text(
    //       '确定',
    //       style: TextStyle(color: Colors.red),
    //     ),
    //     cancel: Text(
    //       '取消',
    //       style: TextStyle(color: Colors.cyan),
    //     ),
    //   ),
    //   minDateTime: DateTime.parse('1980-05-12'),
    //   maxDateTime: DateTime.parse('2100-05-12'),
    //   initialDateTime: DateTime.now(),
    //   dateFormat: "yyyy-mm-dd",
    //   locale: DateTimePickerLocale.zh_cn,
    //   onCancel: () {
    //     print('onCancle');
    //   },
    //   onChange: (dateTime, List<int> index) {
    //     setState(() {
    //       _dateTime = dateTime;
    //     });
    //   },
    //   onConfirm: (dateTime, List<int> index) {
    //     setState(() {
    //       _dateTime = dateTime;
    //     });
    //   },
    // );
  }
  // void _showDatePicker() {
  //   DatePicker.showDatePicker(
  //     context,
  //     onMonthChangeStartWithFirstDate: true,
  //     pickerTheme: DateTimePickerTheme(
  //       showTitle: true,
  //       confirm: Text('custom Done', style: TextStyle(color: Colors.red)),
  //     ),
  //     minDateTime: DateTime.parse("1980-05-12"),
  //     maxDateTime: DateTime.parse("2100-05-12"),
  //     initialDateTime: _dateTime,
  //     dateFormat: "yyyy-mm-dd",
  //     locale: DateTimePickerLocale.zh_cn,
  //     onClose: () => print("----- onClose -----"),
  //     onCancel: () => print('onCancel'),
  //     onChange: (dateTime, List<int> index) {
  //       setState(() {
  //         _dateTime = dateTime;
  //       });
  //     },
  //     onConfirm: (dateTime, List<int> index) {
  //       setState(() {
  //         _dateTime = dateTime;
  //       });
  //     },
  //   );
  // }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Flutter第三方时间控件"),
      ),
      body: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          InkWell(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [Text("2019-06-14"), Icon(Icons.arrow_drop_down)],
            ),
            onTap: this._showDatePicker,
          )
        ],
      ),
    );
  }
}
